<?php

/**
 * Created by ymk
 * User: Administrator
 * Date: 2018/6/28
 * Time: 18:05
 */

namespace MeetUp\Model;

use Illuminate\Database\Eloquent\Model;

class TopicLike extends Base
{
    protected $table = 'topic_like';
    protected $primaryKey = 'like_id';
    protected $fillable = ['uid','topicid'];
    //帖子点赞数
    public function number($id){
        return $this->where(['topicid'=>$id])->count();
    }
    //判断用户是否点赞
    public function is_like($topid,$uid){
        return $this->where(['uid'=>$uid,'topicid'=>$topid])->first();
    }
    //取消点赞
    public function cancel_like($topid,$uid){
        return $this->where(['uid'=>$uid,'topicid'=>$topid])->delete();
    }
    //点赞
    public function like($topid,$uid){
        return $this->create(['uid'=>$uid,'topicid'=>$topid]);
    }
}